using System;
using System.IO;
using System.Net;

namespace Demo
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            Test.DownloadFile("http://2.bp.blogspot2.com/-jRE9siroiGE/TW14_hPQ5BI/AAAAAAAAB0U/4Jy6ZUlGqzw/s1600/jayson%2B%252813%2529.jpg", @"D:\bm.jpg");
        }
    }

    public class Test
    {
        public Test()
        {
        }

        public static void DownloadFile(string url, string fileName)
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
                HttpWebResponse response = (HttpWebResponse) request.GetResponse();
                BinaryReader reader = new BinaryReader(response.GetResponseStream());
//                BinaryWriter writer = new BinaryWriter(File.Create(fileName,1024));
                FileStream fileStream = new FileStream(fileName,FileMode.OpenOrCreate,FileAccess.ReadWrite);
                byte[] buffer = new byte[1024];
                int bytesRead = reader.Read(buffer,0,buffer.Length);
                long downloadedSize = 0;
                while (bytesRead>0)
                {
//                    writer.Write(buffer,0,buffer.Length);
                    fileStream.Write(buffer,0,bytesRead);
                    downloadedSize += bytesRead;
                    Console.WriteLine(downloadedSize/1024);
                    bytesRead = reader.Read(buffer, 0, buffer.Length);
                }
                fileStream.Close();
//                writer.Close();
                reader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadLine();
        }
    }
}